/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <vector>
#include "OgreMath/OgreVector3.h"
#include "OgreMath/OgreVector4.h"

class Spline
{
public:
	Spline(){m_Sectors.clear();}
	Spline(std::vector<Ogre::Vector3> vPoints, bool bClosed);
	void setPoints(std::vector<Ogre::Vector3> vPoints, bool bClosed=false);

	Spline(std::vector<Ogre::Vector4> vPoints, bool bClosed);
	void setPoints(std::vector<Ogre::Vector4> vPoints, bool bClosed=false);

	Ogre::Vector3 sample(double fPos, int* piCurrentKey=0) const;
	double getLength() const;

	class CSplineSector
	{
	public:
		Ogre::Vector3 calcSample(double fPos) const;//pos in [0:1]
		double m_aafParams[3][4];
	};
private:
	bool m_bIsTimedSpline;
	void solveLinearSystem(double** ppfMatrix, double* ppfResults, int iMatrixSize);//takes matrices in n+1 x n form
	std::vector<CSplineSector> m_Sectors;
	std::vector<double> m_SectorLengths;
};